#!/bin/sh
LOGDIR=/opt/logs/attendance/
JAR="atcheck.jar"


function start(){
        c="`ps -ef | grep -c ${JAR}`"
        if [ $c -le 1 ]; then
                echo "starting..."
                java -jar ${JAR} -server -Xms128m -Xmx1024m   -Xss512k -XX:-OmitStackTraceInFastThrow  -XX:NewSize=256m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=78 -XX:PermSize=256m -XX:MaxPermSize=256m    >$LOGDIR/error.log  2>&1 >$LOGDIR/error.log &
                echo $! > $LOGDIR/pid.log
                echo "started pid:$!"
        else
                echo "already started pid:`cat $LOGDIR/pid.log`"
                exit 0
        fi
}
function stop(){
        c="`ps -ef | grep -c ${JAR}`"
        echo "$c"
        if [ $c -le 1 ]; then
                echo "not running"
                exit 0
        else
                pid="`cat $LOGDIR/pid.log`"
                echo "stoping pid:$pid ..."
                kill -9 $pid
                echo "" > $LOGDIR/pid.log
        fi
}
function restart(){
        stop;
        sleep 30;
        start;
}

case    "$1"    in

start)
        start
;;
stop)
        stop
;;
restart)
        restart
;;
*)
        echo "require:start|stop|restart"
esac

exit 0

